﻿using System;
using System.Windows.Forms;

namespace iTunes_Media_Keys
{
    public delegate void AddHotKeyHandler(KeyEventArgs k, Onyeyiri.HotKeyModifier h, iTunesFunctions i);

    public partial class AddHotKey : Form
    {
        public event AddHotKeyHandler HotKeyAdded;
        //
        private KeyEventArgs k;

        public AddHotKey()
        {
            InitializeComponent();
        }

        #region Form Events

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            textBox1.Text = e.KeyCode.ToString();
            //
            k = e;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
                MessageBox.Show("You must designate a key.");
                return;
            }
            if (comboBox1.SelectedIndex < 0 || comboBox1.SelectedIndex > 13)
            {
                MessageBox.Show("You must select a function for the HotKey to do.");
                return;
            }
            //
            if (radioButton1.Checked)
                HotKeyAdded(k, Onyeyiri.HotKeyModifier.Alt, (iTunesFunctions)(comboBox1.SelectedIndex + 1));
            else if (radioButton2.Checked)
                HotKeyAdded(k, Onyeyiri.HotKeyModifier.Control, (iTunesFunctions)(comboBox1.SelectedIndex + 1));
            else if (radioButton3.Checked)
                HotKeyAdded(k, Onyeyiri.HotKeyModifier.Shift, (iTunesFunctions)(comboBox1.SelectedIndex + 1));
            else if (radioButton4.Checked)
                HotKeyAdded(k, Onyeyiri.HotKeyModifier.Windows, (iTunesFunctions)(comboBox1.SelectedIndex + 1));
            else
            {
                MessageBox.Show("You must select a modifier.");
                return;
            }
            //
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion

        #region Radio Buttons

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                radioButton2.Checked = false;
                radioButton3.Checked = false;
                radioButton4.Checked = false;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {
                radioButton1.Checked = false;
                radioButton3.Checked = false;
                radioButton4.Checked = false;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                radioButton1.Checked = false;
                radioButton2.Checked = false;
                radioButton4.Checked = false;
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked)
            {
                radioButton1.Checked = false;
                radioButton2.Checked = false;
                radioButton3.Checked = false;
            }
        }

        #endregion
    }
}
